//
//  DetailViewController.m
//  FruitVIP
//
//  Created by 孙艳玲 on 15/5/21.
//  Copyright (c) 2015年 孙艳玲. All rights reserved.
//

#import "DetailViewController.h"

#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

@interface DetailViewController ()

@end

@implementation DetailViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor  whiteColor];
    self.navigationItem.title = @"新西兰特级嘎啦果";

    [self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor colorWithRed:110.0 / 255.0 green:78.0 / 255.0 blue:71.0 / 255.0 alpha:1]}];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:255.0/255.0 green:206.0 / 255.0 blue:0 / 255.0 alpha:1];
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    
    self.myDetailScorll = [[DetailScorll alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 30)];
    self.myDetailScorll.carButtonDelegate = self;
    self.myDetailScorll.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.myDetailScorll];
    
 
    UIImageView *backImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 30)];
    UIImage *image = [UIImage imageNamed:@"back.png"];
    image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    backImage.contentMode = UIViewContentModeScaleAspectFit;
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 5, 10, 20);
    [button setBackgroundImage:image forState:UIControlStateNormal];
    [button addTarget:self action:@selector(leftButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [backImage addSubview:button];
    UITapGestureRecognizer *backTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(leftButtonAction)];
    [backImage addGestureRecognizer:backTap];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backImage];

   
    
    UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT - 49 - 64, SCREEN_WIDTH, 49)];
    footView.backgroundColor = [UIColor blackColor];
    [self.view addSubview:footView];
    
    
    UIButton *firstButton = [UIButton buttonWithType:UIButtonTypeCustom];
    firstButton.frame = CGRectMake(10, 0, 40, 40);
    [firstButton setImage:[UIImage imageNamed:@"shouye.png"] forState:UIControlStateNormal];
    [firstButton addTarget:self action:@selector(firstButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:firstButton];
    
    UIButton *secondButton = [UIButton buttonWithType:UIButtonTypeCustom];
    secondButton.frame = CGRectMake(firstButton.frame.origin.x + firstButton.frame.size.width + 30, firstButton.frame.origin.y, 40, 40);
    [secondButton setImage:[UIImage imageNamed:@"car.png"] forState:UIControlStateNormal];
    [secondButton addTarget:self action:@selector(secondButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:secondButton];
    
    UIButton *thirdButton = [UIButton buttonWithType:UIButtonTypeCustom];
    thirdButton.frame = CGRectMake(secondButton.frame.origin.x + secondButton.frame.size.width + 30, secondButton.frame.origin.y, 40, 40);
    [thirdButton setImage:[UIImage imageNamed:@"me.png"] forState:UIControlStateNormal];
    [thirdButton addTarget:self action:@selector(thirdButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:thirdButton];
    
    UIButton *footButton = [UIButton buttonWithType:UIButtonTypeCustom];
    footButton.frame = CGRectMake(SCREEN_WIDTH - SCREEN_WIDTH/3.3, 0, SCREEN_WIDTH/3.3, footView.frame.size.height);
    footButton.backgroundColor = [UIColor colorWithRed:242.0 / 255.0 green:204.0 / 255.0 blue:49.0 / 255.0 alpha:1];
    [footButton setTitle:@"加入购物车" forState:UIControlStateNormal];
    [footButton setTitleColor:[UIColor colorWithRed:71.0 / 255.0 green:61.0 / 255.0 blue:55.0 / 255.0 alpha:1] forState:UIControlStateNormal];
    footButton.titleLabel.font = [UIFont systemFontOfSize:17];
    [footButton addTarget:self action:@selector(footButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [footView addSubview:footButton];
    
}


- (void)leftButtonAction
{
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = NO;
    
    
}

- (void)firstButtonAction
{
    //self.tabBarController.tabBar.hidden = NO;
    [self.navigationController popViewControllerAnimated:YES];
    //self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:0];
}
- (void)secondButtonAction
{
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
}
- (void)thirdButtonAction
{
    MyselfViewController *myVC = [[MyselfViewController alloc] init];
    [self.navigationController pushViewController:myVC animated:NO];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)footButtonAction
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"恭喜您成功加入购物车"delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
    
    //     self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];
}

- (void)carButtonAction
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"恭喜您成功加入购物车"delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alert show];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
